# -*- coding:utf-8 -*-

# before do a long work
# set_workload(1)
# start()
# add_workload(x) compute the all workload to add
# add_workloaded(x) working and add the workloaded
# get_rate() get the progress(0~100)
# is_running() checking the status
# stop() calling it, after everything is done or want to notify the stopping

running = False
workload = 0
workloaded = 0


def is_running():
    global running
    return running


def start():
    global running
    running = True


def stop():
    global running
    running = False


def set_workload(_workload):
    global workload
    global workloaded
    workload = _workload
    workloaded = 0


def add_workload(_workload):
    global workload
    workload += _workload


def process(_workloaded):
    global workloaded
    workloaded += _workloaded


def get_rate():
    global workload
    global workloaded
    if workload == 0:
        return 100
    return (workloaded*100)/workload